public class Demo4_19 {
    //字符串中出现的第一个唯一字符
    public static int firstUniChar(String s) {
        int[] count = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            count[ch - 'a']++;
        }
        //已经统计好，再遍历字符串
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (count[ch - 'a'] == 1) {
                return i;
            }
        }
        return -1;//没有找到
    }

    public static void main(String[] args) {
        String s = "abbadc";
        System.out.println(firstUniChar(s));
    }
}